///*
// * To change this template, choose Tools | Templates
// * and open the template in the editor.
// */
//package managedbean;
//
//import java.io.InputStream;
//import java.sql.ResultSet;
//import javax.annotation.Resource;
//import javax.faces.bean.ManagedBean;
//import javax.faces.bean.SessionScoped;
//import java.util.HashMap;
//import javax.faces.context.FacesContext;
//import javax.servlet.ServletOutputStream;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
//import javax.sql.DataSource;
//import net.sf.jasperreports.engine.JRException;
//import net.sf.jasperreports.engine.JRResultSetDataSource;
//import net.sf.jasperreports.engine.JasperRunManager;
//
///**
// *
// * @author AdminNUS
// */
////@Named(value = "salesLeadReportPDFBean")
////@SessionScoped
//@ManagedBean(name="salesLeadReportPDFBean")
//@SessionScoped 
//public class SalesLeadReportPDFBean {
//    @Resource(name = "macteamData")
//    private DataSource macteamData;
//    
//
//    /** Creates a new instance of SalesLeadReportPDFBean */
//    public SalesLeadReportPDFBean() {
//    }
//    
//    public void exportReportToPdf() {
//        
//        try
//{
//            String strSQL = "SELECT saleslead.`ID`, saleslead.`ARCHIVED`, saleslead.`COMPANYNAME`, saleslead.`CREATEDAT`, saleslead.`FIRSTNAME`, saleslead.`JOBTITLE`, saleslead.`LASTNAME`, saleslead.`TITLE`" + 
//            "FROM `saleslead` saleslead";
//            
//            ResultSet rsEvents = macteamData.getConnection().prepareStatement(strSQL).executeQuery();
//            JRResultSetDataSource jrResultSetDataSource = new JRResultSetDataSource(rsEvents);
//
//            //InputStream reportStream = ((HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true)).getServletContext().getResourceAsStream(null);
//            InputStream reportStream = ((HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true)).getServletContext().getResourceAsStream("/jasperreports/saleLeadReport.jasper");
//            
//            ((HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse()).setContentType("application/pdf");     
//            ServletOutputStream outputStream = ((HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse()).getOutputStream();
//            HashMap jasperParameter = new HashMap();
//        
//            //jasperParameter.put("IMAGEPATH", "http://localhost:8080/MyFace2Organizer-war/jasperreports/cherry.jpg");
//            JasperRunManager.runReportToPdfStream(reportStream, outputStream, jasperParameter, jrResultSetDataSource);
//            
//
//            outputStream.flush();
//
//            outputStream.close();
//            
//            }
//
//        catch (JRException jrex)
//
//        {
//
//            System.out.println("********** Jasperreport Exception");
//
//            jrex.printStackTrace();
//
//        }
//
//        catch (Exception ex)
//
//        {
//
//            ex.printStackTrace();
//
//        }
//}
//
// 
//}
